package org.example.now.async.config;

import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
import org.springframework.stereotype.Component;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Component
public class ExcelExportThreadPoolConfig {
    private static final int CPU_SIZE = Runtime.getRuntime().availableProcessors();

    @Bean(value = "exportThreadPoolExecutor")
    public ThreadPoolExecutor poolExecutor(){
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(CPU_SIZE * 2,CPU_SIZE * 2,
                3, TimeUnit.MINUTES,new LinkedBlockingDeque<>(20),
                new CustomizableThreadFactory("文件导出线程池"));
        threadPoolExecutor.prestartAllCoreThreads();
        return threadPoolExecutor;
    }
}
